<template>
  <div class="article-detail-page">
    <nav class="nav">
      <span @click="$router.back()" class="back">&lt;</span> 面经详情
    </nav>
    <header class="header">
      <h1>{{ articleDetail.stem }}</h1>
      <p>{{ articleDetail.createdAt }} | {{ articleDetail.views }} 浏览量 | {{ articleDetail.likeCount }} 点赞数</p>
      <p>
        <img
          :src="articleDetail.creatorAvatar"
          alt=""
        />
        <span>{{ articleDetail.creatorName }}</span>
      </p>
    </header>
    <main class="body">
      {{ articleDetail.content }}
    </main>
  </div>
</template>

<script>
/*
  路由跳转
  1. 查询参数
  传值: $router.push(/路径?key=value)
  接值: $route.query.xxx
  2. 动态路由
  传值: $router.push(/路径/value)
  接值: $route.params.xxx
  注意点: 配置路由规则 path: '/路径/:id'
  路由回退
  $router.back()
*/
// 请求地址: https://mock.boxuegu.com/mock/3083/articles/:id
// 请求方式: get
import axios from "axios";
export default {
  name: "ArticleDetailPage",
  data() {
    return {
      articleDetail: {}
    };
  },
  created() {
    console.log('文章详情');
    this.getArticleDetail()
  },
  methods: {
    async getArticleDetail() {
      const id = this.$route.params.id;
      const res = await axios.get(
        `https://mock.boxuegu.com/mock/3083/articles/${id}`
      );
      console.log(res);
      this.articleDetail = res.data.result
    },
  },
};
</script>

<style lang="less" scoped>
.article-detail-page {
  .nav {
    height: 44px;
    border-bottom: 1px solid #e4e4e4;
    line-height: 44px;
    text-align: center;
    .back {
      font-size: 18px;
      color: #666;
      position: absolute;
      left: 10px;
      top: 0;
      transform: scale(1, 1.5);
    }
  }
  .header {
    padding: 0 15px;
    p {
      color: #999;
      font-size: 12px;
      display: flex;
      align-items: center;
    }
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
  }
  .body {
    padding: 0 15px;
  }
}
</style>